    /*
 *态势回放功能模块
 */
define("func/tshf", [
    "leaflet",
    "func/base",
    "control/panel",
    "control/draw",
    "control/playback",
    "plugins/mcscroll",
    "data/ajax"
], function (L) {

    //多船态势回放
    L.ICT.Func.add("TSHFMoreShip", {

        Class: L.Class.extend({

            initialize: function () {

                this.menu = L.ict.app.menu;
                this.menuid = 'ict_menu_main_tshf';
                this.config = Project_ParamConfig.tshfConfig;
                this.ictmap = L.ict.app.ictmap;
                this.dateUtil = L.ict.app.util.dateTime;
                this.ajax = new L.ICT.Ajax();
                this.ajax.setTimeout(10 * 60000);

                this._areaPanel = null;
                this._targetPanel = null;
                this._drawPopPanel = null;
                this._layer = null;
                this._playback = null;
                this._areaList = {};
            },

            start: function () {
                this.menu.mainmenu.deactiveOtherSubMenu(this.menuid);
                if(!this.menu.submenu.has(this.menuid)) {
                    this.menu.submenu.add(this.menuid, this.getSubMenuHTML());
                }
                this.menu.submenu.show(this.menuid);
                this._initSubMenuEvts();
            },

            stop: function () {
                if(this._areaPanel) {
                    this._areaPanel.remove();
                }
                if(this._targetPanel) {
                    this._targetPanel.remove();
                }
                if(this.ictmap.map.hasLayer(this._locatelayer)){
                  this.ictmap.map.removeLayer(this._locatelayer);
                }
                this.stopMenu();
                this._areaList = {};
            },

            stopMenu: function () {
                this.ictmap.deactivate();
                this.menu.submenu.destory(this.menuid);
                this.menu.mainmenu.deactiveMenu(this.menuid);
            },

            //获取子菜单HTML
            getSubMenuHTML: function () {
                var html = [];
                html.push('<ul class="submenu_tshf">');
                html.push('<li class="menu_item zdqy"><img src="themes/images/frame/menu_tshf_zdqy.png">&nbsp<label>指定区域</label></li>');
                html.push('<li class="menu_item zdmb"><img src="themes/images/frame/menu_tshf_zdmb.png">&nbsp<label>指定目标</label></li>');
                html.push('</ul>');
                return html.join("");
            },

            //初始化子菜单点击事件
            _initSubMenuEvts: function () {
                var self = this;
                var menuContainer = this.menu.getContainer();
                menuContainer.find(".submenu_tshf .menu_item").on("click", function (event) {
                    event.stopPropagation();
                    var $this = $(this);
                    if(self.ictmap.map.hasLayer(self._locatelayer)){
                      self.ictmap.map.removeLayer(self._locatelayer);
                    }
                    if($this.hasClass("zdqy")) {
                        // 指定区域
                        if(self._areaPanel) {
                            self._areaPanel.remove(false);
                        }
                        if(self.ictmap.map.hasLayer(self._layer)) {
                            self.ictmap.map.removeLayer(self._layer);
                        }
                        self.areaPlayback();
                        self.menu.submenu.hide();

                    } else if($this.hasClass("zdmb")) {
                        //指定目标
                        if(self._targetPanel) {
                            self._targetPanel.remove(false);
                        }
                        self.targetPlayback();
                        self.menu.submenu.hide();
                    }
                });
            },

            //弹出指定区域窗口
            areaPlayback: function () {
                var options = {
                    title: '指定区域',
                    width: 430,
                    height: 350,
                    top: 100,
                    left: 200,
                    contentHTML: this.getAreaHtml()
                };
                var pop = this._areaPanel = new L.ICT.PopPanel(options);
                //窗口关闭事件
                this._areaPanel.on("popPanelRemove", function () {
                    if(this._drawPopPanel) {
                        this._drawPopPanel.remove();
                    }
                    if(this.ictmap.map.hasLayer(this._layer)) {
                        this.ictmap.map.removeLayer(this._layer);
                    }
                    this.stopMenu();
                    this._areaPanel = null;
                }, this);
                pop.show();
                this._initAreaEvts();
                this.ictmap.activate(L.ICT.MapMouseState.RECTANGLE, this._drawCallback, null, this);
            },

            //初始化指定区域事件
            _initAreaEvts: function () {
                var self = this;
                var $container = this._areaPanel.getContainer().find(".areaPlaybackContainer");
                var $msg = $container.find(".msg");
                var $drawContent = $container.find('.drawContent');

                // 设置时间
                var startTime = this.dateUtil.getNewDateTimeBeforHour(this.config.rangeTime);
                startTime = this.dateUtil.formatDateFULL(startTime);
                var endTime = this.dateUtil.formatDateFULL(new Date());
                $container.find(".Wdate.startTime").val(startTime);
                $container.find(".Wdate.endTime").val(endTime);

                // 手动绘制
                $container.find(".draw_by_hand").on("click", function () {
                    if(self.ictmap.map.hasLayer(self._layer)) {
                        self.ictmap.map.removeLayer(self._layer);
                    }
                    if(self.ictmap.map.hasLayer(self._locatelayer)){
                      self.ictmap.map.removeLayer(self._locatelayer);
                    }
                    $(this).addClass('active').siblings().removeClass('active');
                    $drawContent.find('.hand_content').css('display','block');
                    $drawContent.find('.list_content').css('display','none');
                });

                // 列表选择
                $container.find(".draw_by_list").on("click", function () {
                    self.ictmap.deactivate();
                    if(self.ictmap.map.hasLayer(self._layer)) {
                        self.ictmap.map.removeLayer(self._layer);
                    }
                    if(self._drawPopPanel) {
                        self._drawPopPanel.remove();
                    }
                    $(this).addClass('active').siblings().removeClass('active');
                    $drawContent.find('.hand_content').css('display','none');
                    $drawContent.find('.list_content').css('display','block');
                    var url = self.config.areaListUrl;
                    var data = {
                        type: 300,
                        show_status: 1,
                        pageid: 1,
                        pagecount: 999
                    };
                    self.ajax.post(url, data, true, self, function (res, err){
                        self.showAreaListRes(res && res.msg && res.msg.areas || []);
                    });
                });

                //手动绘制事件
                $container.find(".hand_content input[type=radio]").on("click", function (event) {
                    if(self.ictmap.map.hasLayer(self._layer)) {
                        self.ictmap.map.removeLayer(self._layer);
                    }
                    if(self._drawPopPanel) {
                        self._drawPopPanel.remove();
                    }
                    var type = $(this).val();
                    if(type == "circle") {
                        self.ictmap.activate(L.ICT.MapMouseState.CIRCLE, self._drawCallback, null, self);
                    } else if(type == "rect") {
                        self.ictmap.activate(L.ICT.MapMouseState.RECTANGLE, self._drawCallback, null, self);
                    } else if(type == "polygon") {
                        self.ictmap.activate(L.ICT.MapMouseState.POLYGON, self._drawCallback, null, self);
                    } else if(type == "sector") {
                        self.ictmap.activate(L.ICT.MapMouseState.SECTOR, self._drawCallback, null, self);
                    }
                });

                //日期控件
                $container.find("input[type=text]").on("click", function () {
                    var config = {
                        readOnly: true,
                        dateFmt: 'yyyy-MM-dd HH:mm:ss'
                    };
                    WdatePicker(config);
                });

                //回放按钮点击事件
                $container.find(".playbackbtn").on("click", function (event) {
                    $msg.text('');
                    //判断区域
                    if(self._drawPopPanel) {
                        $msg.text('请确认绘制区域！');
                        return;
                    }
                    if(!self.ictmap.map.hasLayer(self._layer)) {
                        $msg.text('请绘制或选择区域！');
                        return;
                    }
                    //判断时间
                    var startTime = $container.find(".startTime").val();
                    var endTime = $container.find(".endTime").val();
                    var checkRes = self.dateUtil.checkStrartEndTime(startTime, endTime, 3 * 30);
                    if(!checkRes.result) {
                        $msg.text(checkRes.msg);
                        return;
                    }
                    startTime = self.dateUtil.getCusUnixTime(startTime);
                    endTime = self.dateUtil.getCusUnixTime(endTime);

                    //发送请求
                    var data = {};
                    data.limit = self.config.limit;
                    data.mode = Project_ParamConfig.CurrentMode;
                    data.startTime = startTime;
                    data.endTime = endTime;
                    var url = self.config.version === 'mysql' ? self.config.areaUrl : self.config.areaUrlHive;
                    if(self._layer instanceof L.Circle) {
                        url = self.config.areaUrl_circle;
                        data.cirlon = self._layer.getLatLng().lng;
                        data.cirlat = self._layer.getLatLng().lat;
                        data.radius = self._layer.getRadius();
                    } else if(self._layer instanceof L.Rectangle) {  // 矩形实例同样也是多边形实例，故矩形必须写在前面
                        url = self.config.version === 'mysql' ? self.config.areaUrl : self.config.areaUrlHive;
                        var bounds = self._layer.getBounds();
                        data.ldlon = bounds.getSouthWest().lng; //左下经度
                        data.ldlat = bounds.getSouthWest().lat; //左下纬度
                        data.rulon = bounds.getNorthEast().lng;
                        data.rulat = bounds.getNorthEast().lat;
                    } else if(self._layer instanceof L.Polygon) {
                        url = self.config.areaUrl_polygon;
                        var lonarr = [], latarr = [];
                      
                        var latlngs = self._layer.getLatLngs()[0];
                        for (var i = 0, len = latlngs.length; i < len; i++) {
                            lonarr.push(latlngs[i].lng);
                            latarr.push(latlngs[i].lat);
                        }
                        lonarr.push(latlngs[0].lng);
                        latarr.push(latlngs[0].lat);
                        data.lonStrArr = lonarr.join('~');
                        data.latStrArr = latarr.join('~');
                    }  else if (self._layer instanceof L.Sector){
                        url = self.config.areaUrl_sector;
                        data.lon = self._layer.getLatLng().lng;
                        data.lat = self._layer.getLatLng().lat;
                        data.radius = self._layer.getMaxRadius();
                        data.radsmal = self._layer.getMinRadius();
                        data.startDeg = self._layer._startAngle < 270 ? self._layer._startAngle + 90 : self._layer._startAngle - 270;
                        data.endDeg = self._layer._endAngle < 270 ? self._layer._endAngle + 90 : self._layer._endAngle - 270;
                    }
                    self.ajax.abort();
                    self.ajax.post(url, data, true, self, function (res, error) {
                        if(!this._areaPanel) {
                            return;
                        }
                        if(error) {
                            console.error(error.statusText);
                            return;
                        }
                        if(res.state !== 1 || !res.msg || !res.msg.shipList || !res.msg.shipList.length) {
                            console.error(res.msg.error);
                            $msg.text("没有态势回放数据！");
                            return;
                        }
                        //回放
                        this._areaPanel.remove(false);
                        this._areaPanel = null;
                        this.stopMenu();
                        this.playBack(res);
                    });
                });
            },

            // 显示区域列表
            showAreaListRes:function (data){
                var $container = this._areaPanel.getContainer().find(".areaPlaybackContainer");
                var $arealist = $container.find('.drawContent').find('.list_content');
                this._arealistData = data;
                var html = [];
                var $listDiv = $('<div class="listDiv"></div>');
                html.push('<ul class="listul">');
                for (var i = 0, len = data.length; i < len; i++){
                    html.push('<li data-id = "' + data[i]['properties']['id'] + '">');
                    html.push('<label><input type="radio" name="areaSelect">&nbsp&nbsp' + data[i]['properties']['name'] + '</label>');
                    html.push('<button type="button" class="btn btn-link areaLocate">定位</button>');
                    html.push('</li>');
                }
                html.push('</ul>');
                $listDiv.html(html.join(''));
                $arealist.html($listDiv);
                $listDiv.mCustomScrollbar({ theme: "minimal-dark", axis:'y'});
                this._initAreaListEvt($arealist);
            },

            _initAreaListEvt:function ($arealist) {
                // 选择
                $arealist.find('input[name="areaSelect"]').on('click', function (e) {
                    var id = $(e.currentTarget).parent().parent().data('id');
                    var areaInfo = this.getAreaDataById(id);
                    if (!areaInfo) return;
                    if(this.ictmap.map.hasLayer(this._layer)){
                      this.ictmap.map.removeLayer(this._layer);
                    }
                    if(this.ictmap.map.hasLayer(this._locatelayer)){
                      this.ictmap.map.removeLayer(this._locatelayer);
                    }
                    this._layer = L.ict.app.util.tool.convertGeoJsonToLeafletLayer(areaInfo);
                    this.ictmap.map.addLayer(this._layer);
                }.bind(this));

                // 定位
                $arealist.find('.areaLocate').on('click', function (e) {
                    var id = $(e.currentTarget).parent().data('id');
                    var chk = $(e.currentTarget).parent().find('input[name="areaSelect"]')[0].checked;
                    var areaInfo = this.getAreaDataById(id);
                    if (!areaInfo) return;
                    if(this.ictmap.map.hasLayer(this._locatelayer)){
                      this.ictmap.map.removeLayer(this._locatelayer);
                    }
                    // 定位图层
                    if (chk) {
                      this.ictmap.map.fitBounds(this._layer.getBounds());
                    } else {
                      this._locatelayer = L.ict.app.util.tool.convertGeoJsonToLeafletLayer(areaInfo);
                      this.ictmap.map.addLayer(this._locatelayer);
                      this.ictmap.map.fitBounds(this._locatelayer.getBounds());
                    }
                }.bind(this));
            },

            getAreaDataById:function (id) {
                if (this._arealistData && this._arealistData.length) {
                    for (var i = 0, len = this._arealistData.length; i < len; i++){
                        if (this._arealistData[i]['properties']['id'] === Number(id)) {
                            return this._arealistData[i];
                        }
                    }
                }
            },

            //绘图回调
            _drawCallback: function (e) {
                var layer = e.layer;
                var layerType = e.layerType;
                this.ictmap.map.addLayer(layer);
                // 检查范围是否越界
                var bounds = layer.getBounds();
                if (L.ict.app.util.tool.isLatLngsOutExtend(bounds)){
                    this.ictmap.map.removeLayer(layer);
                    L.ict.app.util.dialog.error('错误', '您绘制的区域超出合法范围！');
                    return;
                }
                //加图层
                this._layer = layer;
                // 弹出编辑框
                if(this._drawPopPanel) {
                    this._drawPopPanel.remove();
                }
                this._drawPopPanel = new L.ICT.DrawPopPanel(layer, layerType);
                this._drawPopPanel.on("popPanelRemove", function () {
                    this._drawPopPanel = null;
                }, this);
                this._drawPopPanel.show();
                //可编辑
                if(layer.editing) {
                    layer.editing.enable();
                    layer.on("edit", function (o) {
                        this._drawPopPanel.updateContent();
                    }, this);
                }
            },

            //弹出指定目标窗口
            targetPlayback: function () {
                var options = {
                    title: '指定目标',
                    width: 430,
                    height: 480,
                    top: 100,
                    left: 200,
                    contentHTML: this.getTargetHtml()
                };
                var pop = this._targetPanel = new L.ICT.PopPanel(options);
                //窗口关闭事件
                this._targetPanel.on("popPanelRemove", function () {
                    this.stopMenu();
                    this.config.playbackList = [];
                    this._targetPanel = null;
                }, this);
                pop.show();
                this.updateList();
                this._initTargetEvts();
            },

            //指定目标事件
            _initTargetEvts: function () {
                var self = this;
                var $container = this._targetPanel.getContainer().find(".playbackTargetContainer");
                var $msg1 = $container.find(".msg1");
                var $msg2 = $container.find(".msg2");

                // 设置时间
                var startTime = this.dateUtil.getNewDateTimeBeforHour(this.config.rangeTime);
                startTime = this.dateUtil.formatDateFULL(startTime);
                var endTime = this.dateUtil.formatDateFULL(new Date());
                $container.find(".Wdate.startTime").val(startTime);
                $container.find(".Wdate.endTime").val(endTime);

                //日期控件
                $container.find(".Wdate").on("click", function () {
                    var config = {
                        readOnly: true,
                        dateFmt: 'yyyy-MM-dd HH:mm:ss'
                    };
                    WdatePicker(config);
                });

                //搜索添加
                $container.find(".addBtn").on("click", function (event) {
                    var key = $container.find(".shipIMO").val().trim();
                    $msg1.text("");
                    if(key == "") {
                        $msg1.text("请输入船舶批号！");
                        return;
                    }
                    var url = self.config.getShipByMMSIUrl;
                    var data = {
                        id: key,
                        mode: Project_ParamConfig.CurrentMode
                    };
                    self.ajax.post(url, data, true, this, function (res, error) {
                        if(error) {
                            return;
                        }
                        if(res.state !== 1) {
                            console.error(res.msg.error);
                            $msg1.text("您输入的船舶批号不存在！");
                            return;
                        }
                        var sp = res.msg.list || [];
                        for (var i = 0, len = sp.length; i < len; i++){
                          var nobj = {};
                          nobj.qid = sp[i].num;
                          nobj.id = parseInt((sp[i].mode / 256) % 256) + parseInt(sp[i].mode % 256) + sp[i].num;
                          nobj.shipname = sp[i].sn;
                          nobj.mmsi = sp[i].mmsi;
                          nobj.mode = sp[i].mode;
                          nobj.qmode = sp[i].mode;
                          self.addTarget(nobj);
                        }
                        self.updateList();
                    });

                });

                //删除
                $container.find(".deleteBtn").on("click", function (event) {
                    var $chks = $container.find(".listContent input:checked");
                    $chks.each(function () {
                        var targetId = $(this).parent().parent().data("key");
                        self.deleteTarget(targetId);
                    });
                    self.updateList();
                });

                //全选
                $container.find("input.allchk").on("click", function (event) {
                    var $chks = $container.find(".listContent input[type=checkbox]");
                    if(this.checked == true) {
                        $chks.each(function () { this.checked = true });
                    }
                    // else {
                    //     $chks.each(function () { this.checked = false });
                    // }

                });

                //回放
                $container.find(".playbackBtn").on("click", function (event) {
                    $msg2.text("");
                    var $chks = $container.find(".listContent input:checked"),
                        chkTargets = [];
                    $chks.each(function () {
                        var id = $(this).parent().parent().data("key");
                        var target = self.getTargetById(id);
                        chkTargets.push(target);
                    });
                    if(chkTargets.length <= 0) {
                        $msg2.text("请选择回放目标！");
                        return;
                    }
                    //判断时间
                    var startTime = $container.find(".startTime").val();
                    var endTime = $container.find(".endTime").val();
                    var chkt = self.dateUtil.checkStrartEndTime(startTime, endTime, 3 * 30);
                    if(!chkt.result) {
                        $msg2.text(chkt.msg);
                        return;
                    }
                    startTime = self.dateUtil.getCusUnixTime(startTime);
                    endTime = self.dateUtil.getCusUnixTime(endTime);

                    var url = self.config.moreshipUrl;
                    var data = {};
                    var modeArr = [];
                    var shipIdArr = [];
                    for(var i = 0; i < chkTargets.length; i++) {
                        modeArr.push(chkTargets[i].qmode);
                        shipIdArr.push(chkTargets[i].qid);
                    }
                    data.modeArr = modeArr.join("~");
                    if(Project_ParamConfig.CurrentMode === 0) { //融合模式下只传一个零
                        data.modeArr = 0;
                    }
                    data.shipIdArr = shipIdArr.join("~");
                    data.startTime = startTime;
                    data.endTime = endTime;
                    /// test-start
                    // $.getJSON('./data/playback1.json', function (res) {
                    //     //回放
                    //     self._targetPanel.remove(false);
                    //     self._targetPanel = null;
                    //     self.stopMenu();
                    //     self.playBack(res);
                    // });
                    /// test -end

                    self.ajax.abort();
                    self.ajax.post(url, data, true, self, function (res, error) {
                        if(!this._targetPanel) {
                            return;
                        }
                        if(error) {
                            console.error(error.statusText);
                            return;
                        }
                        if(res.state !== 1 || !res.msg || !res.msg.shipList || !res.msg.shipList.length) {
                            console.error(res.msg.error);
                            $msg2.text("没有态势回放数据！");
                            return;
                        }
                        //回放
                        this._targetPanel.remove(false);
                        this._targetPanel = null;
                        this.stopMenu();
                        this.playBack(res);
                    });

                });
            },

            _listContentEvt: function (){
              var $container = this._targetPanel.getContainer().find(".playbackTargetContainer");
              $container.find(".listContent input[type=checkbox]").on("click", function (event){
                var allchk = $container.find("input.allchk");
                if (!this.checked && allchk[0].checked){
                  allchk[0].checked = false;
                }
              });
            },

            //添加回放船舶
            addTarget: function (target) {
                if(this.config.playbackList.length == 0) {
                    this.config.playbackList.push(target);
                } else {
                    isadd = true;
                    for(var i = 0, len = this.config.playbackList.length; i < len; i++) {
                        if(this.config.playbackList[i].id == target.id) {
                            isadd = false;
                            break;
                        }
                    }
                    if(isadd) {
                        this.config.playbackList.push(target);
                    }
                }
            },

            //通过id删除指定目标列表中的船舶
            deleteTarget: function (targetId) {
                var targets = this.config.playbackList;
                var index = null;
                for(var i = 0, len = targets.length; i < len; i++) {
                    if(targets[i].id == targetId) {
                        index = i;
                        break;
                    }
                }
                if(index !== null) {
                    targets.splice(index, 1);
                }
            },

            //通过id获取船舶
            getTargetById: function (targetId) {
                var targets = this.config.playbackList,
                    target = null;
                for(var i = 0, len = targets.length; i < len; i++) {
                    if(targets[i].id == targetId) {
                        target = targets[i];
                        break;
                    }
                }
                return target;
            },

            //更新指定目标船舶列表
            updateList: function () {
                var $container = this._targetPanel.getContainer().find(".playbackTargetContainer"),
                    $listContent = $container.find(".listContent"),
                    items = this.config.playbackList;
                var html = [];

                html.push('<div class="mscroll"><table>');
                for(var i = 0, len = items.length; i < len; i++) {
                    var qid = items[i].qid;
                    var id = items[i].id;
                    var name = items[i].shipname;
                    html.push('<tr>');
                    html.push('<td class="mmsi" data-key="' + id + '"><label><input type="checkbox" checked>' + '&nbsp&nbsp' + qid + '</label></td><td>' + name + '</td>');
                    html.push('</tr>');
                }
                html.push('</table></div>');
                html = html.join("");
                $listContent.html(html);
                // 事件
                this._listContentEvt();
                //滚动
                $listContent.find(".mscroll").mCustomScrollbar({ theme: "minimal-dark" });
            },

            //调用回放控件
            playBack: function (data) {
                //回放前处理
                this.ictmap.OperateState.tshf = true;
                this.menu.mainmenu.deactivePortInfo(); //退出港口菜单
                this.menu.mainmenu.disableMenu(); //禁用所有一级菜单
                if(!this.config.isShowRealTarget) {
                    this.ictmap.realtarget.hideRealTargetLayer();

                }
                this.config.playbackList = [];
                if(this._playback) {
                    this._playback.close();
                    this._playback = null;
                }
                var beforeZoom = this.ictmap.map.getZoom();
                var beforeCenter = this.ictmap.map.getCenter();
                //回放
                data = data.msg.shipList;
                var self = this;
                this._playback = new L.ICT.Control.PlayBack(data, null, function () {
                    //关闭回放 回调函数
                    self.ictmap.OperateState.tshf = false;
                    self.menu.mainmenu.enableMenu();
                    self.ictmap.map.setView(beforeCenter, beforeZoom);
                    if(!self.config.isShowRealTarget) {
                        self.ictmap.realtarget.addRealTargetLayer();

                    }
                    if(self.ictmap.map.hasLayer(self._layer)) {
                        self.ictmap.map.removeLayer(self._layer);
                    }
                    self._playback = null;
                }, null).show(this.ictmap.map);
            },

            getDrawHtml: function () {
                var html = [];
                html.push('<div class="drawDiv">');
                html.push('<ul class="nav nav-pills">');
                html.push(' <li role="presentation" class="active draw_by_hand"><a href="#">手动绘制</a></li>');
                html.push(' <li role="presentation" class="draw_by_list"><a href="#">列表选择</a></li>');
                html.push('</ul>');
                html.push('<div class="drawContent">');
                html.push(this.getDrawByHandHtml());
                html.push('<div class="list_content" style="display:none;"></div>');
                html.push('</div>');
                html.push('</div>');
                return html.join('');
            },

            getDrawByHandHtml: function () {
                var html = [];
                html.push('<form class="hand_content form-inline" style="display:block;">');
                html.push('<div class="form-group">');
                html.push('<div class="radio"><label><input type="radio" name="drawRadio" value="rect" checked><img src="themes/images/frame/ico_rect.png">矩形</label></div>');
                html.push('<div class="radio"><label><input type="radio" name="drawRadio" value="circle"><img src="themes/images/frame/ico_circle.png">圆形</label></div>');
                html.push('<div class="radio"><label><input type="radio" name="drawRadio" value="polygon"><img src="themes/images/frame/ico_ployon.png">多边形</label></div>');
                html.push('<div class="radio"><label><input type="radio" name="drawRadio" value="sector"><img src="themes/images/frame/ico_sector.png">扇(环)形</label></div>');
                html.push('</div>');
                html.push('</form>');
                return html.join('');
            },

            //获取指定区域HTML
            getAreaHtml: function () {
                var html = [];
                html.push('<div class="areaPlaybackContainer">');
                // html.push('<fieldset class="drawDiv">');
                // html.push('<legend>绘制区域：</legend> ');
                // html.push('<form class="form-inline">');
                // html.push('<div class="form-group">');
                // html.push('<div class="radio"><label><input type="radio" name="drawRadio" value="rect" checked><img src="themes/images/frame/ico_rect.png">矩形</label></div>');
                // html.push('<div class="radio"><label><input type="radio" name="drawRadio" value="circle"><img src="themes/images/frame/ico_circle.png">圆形</label></div>');
                // html.push('<div class="radio"><label><input type="radio" name="drawRadio" value="polygon"><img src="themes/images/frame/ico_ployon.png">多边形</label></div>');
                // html.push('</div>');
                // html.push('</form>');
                // html.push('</fieldset>');
                html.push(this.getDrawHtml());
                html.push('<hr style="margin:10px 0;">');
                html.push('<div class="timeDiv">');
                html.push('<label>时间:</label> <input type="text" class="Wdate startTime"> <label>&nbsp至&nbsp</label> <input type="text" class="Wdate endTime"> ');
                html.push('</div>');
                html.push('<p class="msg"></p>');
                html.push('<div class="btnDiv"><button type="button" class="btn playbackbtn">回放</button></div>');
                html.push('</div>');
                return html.join('');
            },

            //获取指定目标HTML
            getTargetHtml: function () {
                var html = [];
                html.push('<div class="playbackTargetContainer">');
                html.push('  <div class="cbphDiv">');
                html.push('    <label>船舶:</label>');
                html.push('    <input type="text" class="shipIMO">');
                // html.push('    <img src="themes/images/frame/title_search_btn.png" class="icon_search">');
                html.push('    <button class="btn addBtn">添加</button>');
                html.push('  </div>');
                html.push('  <p class="msg msg1"></p>');
                html.push('  <p class="cblb_txt">船舶列表:</p>');
                html.push('  <div class="phlbDiv">');
                // html.push('    <label>船舶批号列表:</label>');
                html.push('    <label><input type="checkbox" class="allchk" checked>全选</label>');
                html.push('    <button class="btn deleteBtn">删除</button>');
                html.push('  </div>');
                html.push('  <div class="shiplist">');
                html.push('    <div><table><tr><td>批号</td><td>船舶名</td></tr></table></div>');
                html.push('    <hr>');
                html.push('    <div class="listContent"></div>');
                html.push('  </div>');
                html.push('  <p class="msg msg2"></p>');
                html.push('  <hr>  ');
                html.push('  <div class="timeDiv"><label>时间:</label> <input type="text" class="Wdate startTime"> <label>&nbsp至&nbsp</label> <input type="text" class="Wdate endTime"></div>');
                html.push('  <div class="btnDiv"><button type="button" class="btn playbackBtn">回放</button></div>');
                html.push('</div>');
                return html.join('');
            }
        })

    });

    //单船态势回放
    L.ICT.Func.add("TSHFOneShip", {

        Class: L.Class.extend({

            initialize: function () {
                this.config = Project_ParamConfig.tshfConfig;
                this.ictmap = L.ict.app.ictmap;
                this.menu = L.ict.app.menu;
                this.dateUtil = L.ict.app.util.dateTime;
                this.ajax = new L.ICT.Ajax();

                this._popPanel = null;
                this._playback = null;
            },

            start: function () {
                if(this._popPanel) { this._popPanel.remove(); }
                this._initUi();
                this._initEvts();
            },

            stop: function () {
                if(this._popPanel) { this._popPanel.remove(); }
                if(this._playback) { this._playback.close(); }
            },

            _initUi: function () {
                var options = {
                    title: '态势回放',
                    width: 430,
                    height: 160,
                    contentHTML: this.getContentHtml()
                };
                var pop = this._popPanel = new L.ICT.PopPanel(options);
                //窗口关闭
                this._popPanel.on("popPanelRemove", function () {
                    this._popPanel = null;
                }, this);
                pop.show();
            },

            getContentHtml: function () {
                var html = [];
                html.push('<div class="tshf_oneship_container">');
                html.push('<div class="timeDiv">');
                html.push('<label>时间：</label>');
                html.push('<input type="text" class="Wdate startTime">');
                html.push('<label>&nbsp 至 &nbsp</label>');
                html.push('<input type="text" class="Wdate endTime">');
                html.push('</div>');
                html.push('<p class="msg"></p>');
                html.push('<div class="btnDiv">');
                html.push('<button type="button" class="confirm">确定</button>');
                html.push('<button type="button" class="cancel">取消</button>');
                html.push('</div>');
                html.push('</div>');
                return html.join("");
            },

            _initEvts: function () {
                var $container = this._popPanel.getContainer().find(".tshf_oneship_container"),
                    $msg = $container.find(".msg"),
                    self = this;

                // 设置时间
                var startTime = this.dateUtil.getNewDateTimeBeforHour(24);
                startTime = this.dateUtil.formatDateFULL(startTime);
                var endTime = this.dateUtil.formatDateFULL(new Date());
                $container.find(".Wdate.startTime").val(startTime);
                $container.find(".Wdate.endTime").val(endTime);

                //日期
                $container.find(".Wdate").on("click", function () {
                    var config = {
                        readOnly: true,
                        dateFmt: 'yyyy-MM-dd HH:mm:ss'
                    };
                    WdatePicker(config);
                });

                //确认
                $container.find(".confirm").on("click", function () {
                    $msg.text("");
                    //判断时间
                    var startTime = $container.find(".startTime").val();
                    var endTime = $container.find(".endTime").val();
                    var chkt = self.dateUtil.checkStrartEndTime(startTime, endTime, 3 * 30);
                    if(!chkt.result) {
                        $msg.text(chkt.msg);
                        return;
                    }
                    startTime = self.dateUtil.getCusUnixTime(startTime);
                    endTime = self.dateUtil.getCusUnixTime(endTime);
                    //多船的接口也适用于单船
                    var url = self.config.moreshipUrl;
                    var sid = self.ictmap.realtarget.currentTarget.options.data.qid;
                    var mode = self.ictmap.realtarget.currentTarget.options.data.qmode;
                    var data = {
                        modeArr: mode,
                        shipIdArr: sid,
                        startTime: startTime,
                        endTime: endTime
                    };
                    self.ajax.abort();
                    self.ajax.post(url, data, true, self, function (res, error) {
                        if(!this._popPanel) {
                            return;
                        }
                        if(error) {
                            console.error(error.statusText);
                            return;
                        }
                        if(res.state !== 1 || !res.msg || !res.msg.shipList || !res.msg.shipList.length) {
                            console.error(res.msg.error);
                            $msg.text("没有态势回放数据！");
                            return;
                        }
                        //进入态势回放状态
                        this._popPanel.remove();
                        this.playBack(res);
                    });
                });

                //取消
                $container.find(".cancel").on("click", function () {
                    self.stop();
                });
            },

            //调用回放控件
            playBack: function (data) {
                this.ictmap.OperateState.tshf = true;
                this.menu.mainmenu.deactivePortInfo();
                this.menu.mainmenu.disableMenu();
                if(!this.config.isShowRealTarget) {
                    this.ictmap.realtarget.hideRealTargetLayer();
                }
                if(this._playback) {
                    this._playback.close();
                    this._playback = null;
                }
                data = data.msg.shipList;
                var beforeZoom = this.ictmap.map.getZoom();
                var beforeCenter = this.ictmap.map.getCenter();
                var self = this;
                this._playback = new L.ICT.Control.PlayBack(data, null, function () {
                    self._playback = null;
                    self.ictmap.OperateState.tshf = false;
                    self.menu.mainmenu.enableMenu();
                    self.ictmap.map.setView(beforeCenter, beforeZoom);
                    if(!self.config.isShowRealTarget) {
                        self.ictmap.realtarget.addRealTargetLayer();
                    }
                }, null).show(this.ictmap.map);
            }
        })
    });

});
